package uplift.project;

import java.util.ArrayList;

import uplift.project.model.VolunteerEvent;
import android.app.ActionBar;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.TabHost;

public class MyEventsTabActivity extends TabActivity {
	public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    setContentView(R.layout.myevents);

		ApplicationData appData = (ApplicationData)this.getApplicationContext();
	    
	    Resources res = getResources(); // Resource object to get Drawables
	    TabHost tabHost = getTabHost();  // The activity TabHost
	    TabHost.TabSpec spec;  // Resusable TabSpec for each tab
	    Intent intent;  // Reusable Intent for each tab

	    // Create an Intent to launch an Activity for the tab (to be reused)
	    if (appData.eventsList.getJoinedEvents().size() == 0){
		    intent = new Intent().setClass(this, NoJoinedEventsActivity.class);
	    } else {
		    intent = new Intent().setClass(this, MyEventsSignedUpActivity.class);
	    }

	    // Initialize a TabSpec for each tab and add it to the TabHost
	    spec = tabHost.newTabSpec("myevents_signedup").setIndicator("Signed Up")
	                  .setContent(intent);
	    tabHost.addTab(spec);

	    // Do the same for the other tabs
	    if (appData.eventsList.getUserCreatedEvents().size() == 0){
		    intent = new Intent().setClass(this, NoCreatedEventsActivity.class);
	    } else {
		    intent = new Intent().setClass(this, MyEventsOrganizingActivity.class);
	    }
	    spec = tabHost.newTabSpec("myevents_organizing").setIndicator("Organizing")
	                  .setContent(intent);
	    tabHost.addTab(spec);

	    tabHost.setCurrentTab(2);
	    
		// set the action bar to have up-navigation enabled
	    ActionBar actionBar = getActionBar();
	    actionBar.setDisplayHomeAsUpEnabled(true);
	}
	
	// handles action item button presses
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		if(item.getItemId() == android.R.id.home) {
			// move up the hierarchy

			Intent i = new Intent(getApplicationContext(), UpliftActivity.class);
			i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			startActivity(i);
		} else if(item.getItemId() == R.id.menu_home) {
			// go to Home screen
			
			Intent i = new Intent(getApplicationContext(), UpliftActivity.class);
			i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			startActivity(i);
		} else if(item.getItemId() == R.id.menu_my_events) {
			// go to My Events screen
			
			Intent i = new Intent(getApplicationContext(), MyEventsTabActivity.class);
			i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			startActivity(i);
		}
		return true;
	}
	
	// set up Action Bar
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
	    MenuInflater inflater = getMenuInflater();
	    inflater.inflate(R.menu.action_bar, menu);
	    menu.getItem(0);
	    return true;
	}
}
